<?php

/**
 * edit a single author
 *
 * @author vbolshov
 */

include dirname(__FILE__) . '/../setup.php';

use bs\Author;
use bs\Renderer;

if ($id = filter_input(INPUT_GET, 'id', FILTER_VALIDATE_INT))
{
	$author = Author::find($id)->fetchOne();
} else {
	$author = new Author();
}

if ('POST' == $_SERVER['REQUEST_METHOD']) {
	$author->name = @$_POST['name'];
	$author->save();
	echo json_encode(array('code' => 'ok', 'data' => $author->toArray()));
	exit;
}

$view = Renderer::getView('editauthor.php');
$view->author = $author;
$view->render();